//
//  WNationTableViewController.swift
//  iiatn
//
//  Created by mine on 18/5/3.
//  Copyright © 2018年 mnine. All rights reserved.
//

import UIKit
import SVProgressHUD

class WNationTableViewController: WCProViewController{
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setheader()
        // 获取首页数据
        weak var weakSelf = self
        WNetwork.shareNetworkTool.loadLatPro() { (mpros) in
            weakSelf!.items = mpros
            weakSelf!.tableView!.reloadData()
            SVProgressHUD.dismiss()
        }
    }
    
    override func loadData() {
        // 获取首页数据
        weak var weakSelf = self
        WNetwork.shareNetworkTool.loadLatPro() { (mpros) in
            weakSelf!.items = mpros
            weakSelf!.tableView!.reloadData()
            weakSelf!.refreshControl?.endRefreshing()
        }
    }
    
    func setheader(){
        //给TableView添加表头页眉
        let headerView:UIView = UIView(frame:CGRect(x:0, y:0, width:SCREENW, height:80))

        let listBtn:UIButton = UIButton(frame:CGRect(x:5, y:50, width:(SCREENW - 20)/2, height:30))
        let mapBtn:UIButton = UIButton(frame:CGRect(x:listBtn.width + 5, y:50, width:(SCREENW - 20)/2, height:30))
        
        listBtn.backgroundColor = WColor(r: 255, g: 189, b: 58, a: 0.5)
        mapBtn.backgroundColor = WColor(r: 86, g: 147, b: 225, a: 0.77)
        
        listBtn.setTitle("国别列表查询", for: .normal)
        mapBtn.setTitle("国别地图全览", for: .normal)
        
        listBtn.setTitleColor(WColor(r: 79, g: 79, b: 79, a: 1), for: .normal)
        mapBtn.setTitleColor(WColor(r: 79, g: 79, b: 79, a: 1), for: .normal)
        
        listBtn.setTitleColor(UIColor.gray, for: .highlighted)
        mapBtn.setTitleColor(UIColor.gray, for: .highlighted)
        listBtn.setTitleColor(UIColor.gray, for: .selected)
        mapBtn.setTitleColor(UIColor.gray, for: .selected)

        listBtn.titleLabel?.font =  UIFont.systemFont(ofSize: 14)
        mapBtn.titleLabel?.font =  UIFont.systemFont(ofSize: 14)
        
        listBtn.layer.cornerRadius = listBtn.height * 0.08
        listBtn.layer.masksToBounds = true
        listBtn.layer.rasterizationScale = UIScreen.main.scale
        mapBtn.layer.cornerRadius = mapBtn.height * 0.08
        mapBtn.layer.masksToBounds = true
        mapBtn.layer.rasterizationScale = UIScreen.main.scale
        
        listBtn.setTitleColor(UIColor.gray, for: .highlighted)
        mapBtn.setTitleColor(UIColor.gray, for: .highlighted)
        
        listBtn.addTarget(self, action: #selector(alertList), for: .touchUpInside)
        mapBtn.addTarget(self, action: #selector(toMap), for: .touchUpInside)
        
        
        headerView.addSubview(listBtn)
        headerView.addSubview(mapBtn)
        
        headerView.backgroundColor = UIColor.white
        tableView?.tableHeaderView = headerView
}
    
    func alertList(){
        toGuobie()
    }
    
    func toMap(){
        print("toMap")
        let detailVC = WWebViewToolController()
        detailVC.title="国别地图全览"
        detailVC.open_url = "http://www.china-ofdi.org/api/search"
        navigationController?.pushViewController(detailVC, animated: true)
        
    }
    
    func toGuobie(){
        print("toGuobie")
        let detailVC = WGuoListViewController()
        detailVC.title="国别列表查询"
        navigationController?.pushViewController(detailVC, animated: true)
        
    }
    
}
